package com.hey.mib;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by heer on 2018/8/7.
 */
public class Test {

    public static void main(String[] args) {
//        ProxyUtil proxyUtil = new ProxyUtil(new OphylinkOsl3030FingerEntry());
//        System.out.println(proxyUtil.getIndexString());
//        System.out.println(proxyUtil.getOIDMapping());
        Object object = "1";
        System.out.println(object instanceof String);
    }

    /**
     */
    public static void setDatetime() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String timeCurrent = sdf.format(new Date());
        String[] timeArray = timeCurrent.split(" ");
        String dateTime = timeArray[0];
        String[] dateTimeArray = dateTime.split("-");
        String timeYear = dateTimeArray[0];
        dateTime = String.valueOf(Integer.valueOf(timeYear)-1)+"-"+dateTimeArray[1]+"-"+dateTimeArray[2];
        System.out.println(dateTime);
        execCommand(dateTime,timeArray[1]);
        System.out.println(new Date());
    }

    /**
     */
    public static void restoreDatetime() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String timeCurrent = sdf.format(new Date());
        String[] timeArray = timeCurrent.split(" ");

        String dateTime = timeArray[0];
        String[] dateTimeArray = dateTime.split("-");
        String timeYear = dateTimeArray[0];
        dateTime = String.valueOf(Integer.valueOf(timeYear)+1)+"-"+dateTimeArray[1]+"-"+dateTimeArray[2];
        System.out.println(dateTime);
        execCommand(dateTime,timeArray[1]);
        System.out.println(new Date());
    }

    public static void execCommand(String dateTime,String time){
        String osName = System.getProperty("os.name");
        try {
            Process process = Runtime.getRuntime().exec("net localgroup  "+System.getProperty("user.name")+" /add");
            if (osName.matches("^(?i)Windows.*$")) { // Window
                String cmd;
                cmd = " cmd /c date " + dateTime; // yyyy-MM-dd
                Runtime.getRuntime().exec(cmd);
                cmd = " cmd /c time " + time; //  HH:mm:ss
                Runtime.getRuntime().exec(cmd);
                InputStream fis = process.getInputStream();
                BufferedReader br = new BufferedReader(new InputStreamReader(fis));
                String line;
                while ((line = br.readLine()) != null) {
                    System.out.println(line);
                }
            } else if (osName.matches("^(?i)Linux.*$")) {// Linux
                String command = "date -s " + "\"" + dateTime + " " + time + "\"";// ：yyyy-MM-dd HH:mm:ss
                process = Runtime.getRuntime().exec(command);
            } else {
            }
        } catch (IOException e) {
            e.getMessage();
        }
    }
}
